using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Employee_DeliveryManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string dNo = ((GridViewRow)(((Button)sender).Parent.Parent)).Cells[2].Text;
        string weight = ((GridViewRow)(((Button)sender).Parent.Parent)).Cells[3].Text;
        string dOp = ((GridViewRow)(((Button)sender).Parent.Parent)).Cells[4].Text;
        string serID = ((GridViewRow)(((Button)sender).Parent.Parent)).Cells[5].Text;
        string DA = ((GridViewRow)(((Button)sender).Parent.Parent)).Cells[6].Text;
        string CID = ((GridViewRow)(((Button)sender).Parent.Parent)).Cells[7].Text;
        string FTID = ((GridViewRow)(((Button)sender).Parent.Parent)).Cells[8].Text;
        string Sta = ((GridViewRow)(((Button)sender).Parent.Parent)).Cells[9].Text;
        string RD = ((GridViewRow)(((Button)sender).Parent.Parent)).Cells[10].Text;

        TextBox1.Text = dNo;
        TextBox4.Text = weight;
        TextBox5.Text = dOp;
        TextBox3.Text = serID;
        TextBox7.Text = DA;
        TextBox2.Text = CID;
        TextBox9.Text = FTID;
        TextBox8.Text = Sta;
        TextBox6.Text = RD;
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {

        try
        {
            // New connection
            Connection newCon = new Connection();
            SqlConnection con = newCon.ConStr;

            // open conneciton
            con.Open();

            // prepare command
            SqlCommand cmd = new SqlCommand("insert into Delivery values(@dNo , @weight, @dOp, @sID, @dA, @cID, @fTID, @sta, @RD)", con);

            cmd.Parameters.AddWithValue("dNo", TextBox1.Text);
            cmd.Parameters.AddWithValue("weight", TextBox2.Text);
            cmd.Parameters.AddWithValue("dOp", TextBox3.Text);
            cmd.Parameters.AddWithValue("sID", TextBox4.Text);
            cmd.Parameters.AddWithValue("dA", TextBox5.Text);
            cmd.Parameters.AddWithValue("cID", TextBox6.Text);
            cmd.Parameters.AddWithValue("fTID", TextBox7.Text);
            cmd.Parameters.AddWithValue("sta", TextBox8.Text);
            cmd.Parameters.AddWithValue("RD", TextBox9.Text);

            // execute query
            cmd.ExecuteNonQuery();

            // reload gridview
            GridView1.DataBind();

            // close connection
            con.Close();
        }
        catch (Exception ex)
        {
            lblError.Text = "Cannot insert new record: " + ex.Message;
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        String tempName = ((GridViewRow)((Control)sender).Parent.Parent).Cells[0].Text;

        Response.Redirect("~/Admin/DeliveryDetail.aspx?deliverynumber=" + tempName);
    }
}
